home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / performance / memory / tinymeter / source / tinymeter_main / gaugeclass.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-20  |  23.9 KB  |  870 lines

  1. /*
  2. ** gaugeclass V0.9 by Tinic Urou
  3. **
  4. ** Class implementation
  5. **
  6. ** tested compilers:
  7. **
  8. ** · DCC 2.6.2
  9. ** · GCC 2.7.0 with libnix V1.0 (libnix is necessary!!)
  10. **
  11. */
  12.  
  13. #include <exec/types.h>
  14. #include <exec/memory.h>
  15. #include <dos/dos.h>
  16. #include <dos/dosextens.h>
  17. #include <intuition/intuition.h>
  18. #include <intuition/gadgetclass.h>
  19. #include <intuition/intuitionbase.h>
  20. #include <intuition/classusr.h>
  21. #include <intuition/imageclass.h>
  22. #include <intuition/gadgetclass.h>
  23. #include <intuition/cghooks.h>
  24. #include <intuition/icclass.h>
  25. #include <intuition/classes.h>
  26. #include <intuition/sghooks.h>
  27. #include <intuition/screens.h>
  28. #include <graphics/gfxbase.h>
  29. #include <graphics/text.h>
  30. #include <graphics/gfxmacros.h>
  31. #include <utility/tagitem.h>
  32. #include <utility/hooks.h>
  33. #include <string.h>
  34. #include "gaugeclass.h"
  35.  
  36. #define col_label       0
  37. #define col_format      1
  38. #define col_base        2
  39. #define col_current     3
  40. #define col_negative    4
  41. #define col_bright      5
  42. #define col_dark        6
  43. #define col_bg          7
  44.  
  45. #define ind_centered    0
  46. #define ind_left        1
  47. #define ind_right       2
  48.  
  49. struct GaugeData
  50. {
  51.     ULONG   min;
  52.     ULONG   max;
  53.     ULONG   current;
  54.     ULONG   base;
  55.     ULONG   old_cur;
  56.     ULONG   old_bas;
  57.     WORD   labelpos;
  58.     UBYTE   fmtind;
  59.  
  60.     ULONG   type;
  61.  
  62.     char    *txtlbl;
  63.     char    *txtfmt;
  64.  
  65.     struct  GAU_Color Colors[GAU_UsedColors];
  66.  
  67.     BOOL    Style3D;
  68.     BOOL    StyleBorder;
  69.     BOOL    StyleBackground;
  70.     BOOL    StyleShadowLabel;
  71.     BOOL    StyleNoGauge;
  72.     BOOL    StyleNoFormat;
  73.     BOOL    StyleNoBase;
  74.  
  75.     struct  TextFont *textFont;
  76.  
  77.     ULONG   Pens[GAU_UsedColors];
  78.     BOOL    PorC[GAU_UsedColors];
  79.  
  80.     BOOL    InitNotDone;
  81.  
  82.     struct  RastPort *nolock_rp;
  83.  
  84.     LONG   histpos;
  85.  
  86.     WORD   text_y;
  87.     struct  Locale *locale;
  88.     char    clocktxt[256];
  89.     char    voltxt[64];
  90.  
  91.     struct  RastPort   *bg_buffer;
  92.     struct  RastPort   *wk_buffer;
  93.     struct  RastPort   *hs_buffer;
  94.  
  95.     WORD   clockpos;
  96.  
  97.     BOOL    highlight;
  98.     WORD    oldclockx;
  99.     WORD    oldclockw;
  100.  
  101.     ULONG   voltype;
  102. };
  103.  
  104. extern ULONG DoSuperMethodA( struct IClass *cl, Object *obj, Msg message );
  105. extern ULONG DoMethod( Object *obj, unsigned long MethodID, ... );
  106. extern ULONG HookEntry();
  107.  
  108. #ifdef __GNUC__
  109. ULONG dispatchGaugeGadget();
  110. #else
  111. static ULONG dispatchGaugeGadget(__a0 Class *cl,__a2 Object *o,__a1 Msg msg);
  112. #endif
  113.  
  114. static ULONG renderGauge(Class *cl,struct Gadget *g, struct gpRender *msg);
  115. void SPrintf(STRPTR buffer, STRPTR format, ...);
  116.  
  117. Class *initGaugeGadgetClass(void)
  118. {
  119.     Class *cl;
  120.     if( cl = (Class *)MakeClass( NULL, "gadgetclass", NULL, sizeof(struct GaugeData), 0) )
  121.     {
  122.     cl->cl_Dispatcher.h_Entry    = (ULONG(*)()) HookEntry;
  123.     cl->cl_Dispatcher.h_SubEntry = (ULONG(*)()) dispatchGaugeGadget;
  124.     return(cl);
  125.     }
  126.     return(0L);
  127. }
  128.  
  129. BOOL freeGaugeGadgetClass( Class *cl )
  130. {
  131.     return FreeClass(cl);
  132. }
  133.  
  134. struct TextAttr topaz_font =
  135. {
  136.     "topaz.font",
  137.     8,
  138.     0,
  139.     FPF_ROMFONT,
  140. };
  141.  
  142. struct TextFont *OpenTopaz()
  143. {
  144.     return((struct TextFont *)OpenFont( &topaz_font));
  145. }
  146.  
  147. void SPrintf(STRPTR buffer, STRPTR format, ...)
  148. {
  149.     struct Library *SysBase= *((void **)4L);
  150.     RawDoFmt( format, (APTR)(&format+1), (void (*)())"\x16\xc0\x4E\x75", buffer);
  151. }
  152.  
  153. int my_strlen(char s[])
  154. {
  155.    int i=0;
  156.    while (s[i]!='\0')++i;
  157.    return(i);
  158. }
  159.  
  160. struct GAU_Color dummycol={ TRUE, 0, 0, 0 };
  161. struct GAU_Color *GetGaugePen(WORD pen){ dummycol.red=pen; return(&dummycol); }
  162.  
  163. GetGaugePenNew(struct gpRender *msg,struct GaugeData *inst,struct GAU_Color *col,ULONG number)
  164. {
  165.     inst->PorC[number]= col->pen ? FALSE    : TRUE;
  166.     inst->Pens[number]= col->pen ? col->red : ObtainBestPenA(msg->gpr_GInfo->gi_Screen->ViewPort.ColorMap, col->red, col->green, col->blue, 0L);
  167. }
  168.  
  169. ULONG newGauge(Class *cl,struct Gadget *g,struct gpRender *msg,struct GaugeData *inst)
  170. {
  171.     struct   TagItem *ti;
  172.  
  173.     ti      = ((struct opSet *)msg)->ops_AttrList;
  174.     if(inst->textFont = (struct TextFont *)GetTagData(GAU_TextFont,OpenTopaz(),ti))
  175.     {
  176.     struct RastPort *dummy;
  177.     if(dummy=(struct RastPort *)AllocVec(sizeof(struct RastPort),0L))
  178.     {
  179.         InitRastPort(dummy);
  180.         dummy->Font=inst->textFont;
  181.  
  182.         inst->min               = GetTagData(GAU_Min,        0, ti);
  183.         inst->max               = GetTagData(GAU_Max,    65535L, ti);
  184.         inst->current           = GetTagData(GAU_Current,32162L, ti);
  185.         inst->base              = GetTagData(GAU_Base,   16384L, ti);
  186.         inst->txtfmt            = (char *)GetTagData(GAU_TextFormat, "%td", ti);
  187.         inst->txtlbl            = (char *)GetTagData(GAU_Label, "Gauge", ti);
  188.         inst->labelpos          = GetTagData(GAU_LabelPos,TextLength(dummy,inst->txtlbl,my_strlen(inst->txtlbl))+4, ti);
  189.  
  190.         inst->Style3D           = GetTagData(GAU_3D,  TRUE, ti);
  191.         inst->StyleBorder       = GetTagData(GAU_Border, TRUE, ti);
  192.         inst->StyleBackground   = GetTagData(GAU_Background, FALSE, ti);
  193.         inst->StyleShadowLabel  = GetTagData(GAU_ShadowLabel, FALSE, ti);
  194.         inst->StyleNoGauge      = GetTagData(GAU_NoGauge,   FALSE, ti);
  195.         inst->StyleNoFormat     = GetTagData(GAU_NoFormat,  FALSE, ti);
  196.         inst->StyleNoBase       = GetTagData(GAU_NoBase,  FALSE, ti);
  197.         inst->fmtind            = GetTagData(GAU_FmtIndent, FALSE, ti);
  198.         inst->type              = GetTagData(GAU_Type, GAU_Type_gauge, ti);
  199.         inst->voltype           = GetTagData(GAU_VolType, 0L, ti);
  200.         inst->locale            = ( inst->type==GAU_Type_clock ) ? (struct Locale *)OpenLocale(NULL) : 0L ;
  201.  
  202.         CopyMem(GetTagData(GAU_ColLabel     , GetGaugePen(2), ti), &inst->Colors[col_label],sizeof(struct GAU_Color));
  203.         CopyMem(GetTagData(GAU_ColFormat    , GetGaugePen(2), ti), &inst->Colors[col_format],sizeof(struct GAU_Color));
  204.         CopyMem(GetTagData(GAU_ColBase      , GetGaugePen(1), ti), &inst->Colors[col_base],sizeof(struct GAU_Color));
  205.         CopyMem(GetTagData(GAU_ColCurrent   , GetGaugePen(3), ti), &inst->Colors[col_current],sizeof(struct GAU_Color));
  206.         CopyMem(GetTagData(GAU_ColNegative  , GetGaugePen(1), ti), &inst->Colors[col_negative],sizeof(struct GAU_Color));
  207.         CopyMem(GetTagData(GAU_ColBrightEdg , GetGaugePen(2), ti), &inst->Colors[col_bright],sizeof(struct GAU_Color));
  208.         CopyMem(GetTagData(GAU_ColDarkEdg   , GetGaugePen(1), ti), &inst->Colors[col_dark],sizeof(struct GAU_Color));
  209.         CopyMem(GetTagData(GAU_ColBackground, GetGaugePen(0), ti), &inst->Colors[col_bg],sizeof(struct GAU_Color));
  210.  
  211.         inst->InitNotDone=TRUE;
  212.         inst->highlight=TRUE;
  213.         inst->oldclockw=0L;
  214.         inst->oldclockx=0L;
  215.  
  216.         FreeVec(dummy);
  217.         return((ULONG)g);
  218.     }
  219.     else return(0L);
  220.     }
  221.     else return(0L);
  222. }
  223.  
  224. freeRPorts(struct GaugeData *inst)
  225. {
  226.     if(inst->bg_buffer)
  227.     {
  228.     FreeBitMap(inst->bg_buffer->BitMap);
  229.     FreeVec(inst->bg_buffer);
  230.     inst->bg_buffer=0L;
  231.     }
  232.  
  233.     if(inst->wk_buffer)
  234.     {
  235.     FreeBitMap(inst->wk_buffer->BitMap);
  236.     FreeVec(inst->wk_buffer);
  237.     inst->wk_buffer=0L;
  238.     }
  239.  
  240.     if(inst->hs_buffer)
  241.     {
  242.     FreeBitMap(inst->hs_buffer->BitMap);
  243.     FreeVec(inst->hs_buffer);
  244.     inst->hs_buffer=0L;
  245.     }
  246.  
  247. }
  248.  
  249. ULONG disposeGauge(Class *cl,struct Gadget *g,struct gpRender *msg)
  250. {
  251.     CloseLocale(((struct GaugeData *)INST_DATA(cl,g))->locale);
  252.     freeRPorts (INST_DATA(cl,g));
  253. }
  254.  
  255. ULONG getGauge(Class *cl,struct Gadget *g,struct gpRender *msg)
  256. {
  257.     struct GaugeData *inst=INST_DATA(cl,g);
  258.     switch (((struct opGet *)msg)->opg_AttrID)
  259.     {
  260.     case    GAU_RPBackground:
  261.         *(((struct opGet *)msg)->opg_Storage)=(ULONG)inst->bg_buffer;
  262.         break;
  263.     case    GAU_Base:
  264.         *(((struct opGet *)msg)->opg_Storage)=(ULONG)inst->base;
  265.         break;
  266.     case    GAU_Current:
  267.         *(((struct opGet *)msg)->opg_Storage)=(ULONG)inst->current;
  268.         break;
  269.     default:
  270.         return((ULONG)FALSE);
  271.         break;
  272.     }
  273.     return((ULONG)TRUE);
  274. }
  275.  
  276. setGauge(Class *cl,struct Gadget *g,struct gpRender *msg)
  277. {
  278.     struct TagItem      *ti,*tstate=((struct opSet *)msg)->ops_AttrList;
  279.     struct GaugeData    *inst=INST_DATA(cl,g);
  280.     struct RastPort     *rp;
  281.     ULONG  t_data;
  282.  
  283.     while(ti=(struct TagItem *)NextTagItem(&tstate))
  284.     {
  285.     t_data=(ULONG)ti->ti_Data;
  286.     switch(ti->ti_Tag)
  287.     {
  288.         case    GAU_Current:
  289.             inst->current=  (ULONG)t_data;
  290.             break;
  291.         case    GAU_Base:
  292.             inst->base=     (ULONG)t_data;
  293.             break;
  294.         case    GAU_Max:
  295.             inst->max=      (ULONG)t_data;
  296.             break;
  297.         case    GAU_VolType:
  298.             inst->voltype=  (ULONG)t_data;
  299.             break;
  300.     }
  301.     }
  302.     if ( FindTagItem(GA_Width,  ((struct opSet *)msg)->ops_AttrList) ||
  303.      FindTagItem(GA_Height, ((struct opSet *)msg)->ops_AttrList) ||
  304.      FindTagItem(GA_Top,    ((struct opSet *)msg)->ops_AttrList) ||
  305.      FindTagItem(GA_Left,   ((struct opSet *)msg)->ops_AttrList) )
  306.     {
  307.     inst->highlight=TRUE;
  308.     inst->InitNotDone=TRUE;
  309.     freeRPorts(inst);
  310.     }
  311. }
  312.  
  313. UBYTE long_2_string_with_thousand(ULONG num, char output[], char point, BOOL negative)
  314. {
  315.     char             output_private[16];
  316.     char             n      = 0;
  317.     char             n_1    = 0;
  318.  
  319.     if(negative)output[n_1++]='-';
  320.     SPrintf(output_private,"%12ld",num);
  321.     while(output_private[n]==0x20)n++;
  322.     for(;(output_private[n]!=0)&(output_private[n]!=0x20);n++)
  323.     {
  324.     output[n_1++]=output_private[n];
  325.     if((n==2)||(n==5)||(n==8)) output[n_1++]=(char)point;
  326.     }
  327.     output[n_1]=0;
  328.     return(n_1);
  329. }
  330.  
  331. char *formattext(ULONG current, ULONG base, ULONG max, char format[], ULONG special)
  332. {
  333.     int         i=0,
  334.         j=0;
  335.     char        temp_str_1[64];
  336.     BOOL        negative;
  337.     static char temp_str[256];
  338.  
  339.     while(format[i]!=0)
  340.     {
  341.     if(format[i]=='%')
  342.     {
  343.         ULONG   dummy=0;
  344.         UBYTE   dummy_2=0,
  345.             dummy_1=0,
  346.             dummy_3=0;
  347.         i++;
  348.         if(format[i]=='t'){dummy_2=1;i++;}
  349.         if(format[i]=='T'){dummy_2=4;i++;}
  350.         if(format[i]=='k'){dummy_1=1;i++;}
  351.         if(format[i]=='m'){dummy_1=2;i++;}
  352.         if(format[i]=='o'){dummy_3=1;i++;}
  353.         if(format[i]=='%'){dummy_2=3;i++;}
  354.         switch(format[i])
  355.         {
  356.         case    'd':
  357.             dummy=current;
  358.             negative=FALSE;
  359.             break;
  360.         case    'b':
  361.             dummy=base;
  362.             negative=FALSE;
  363.             break;
  364.         case    'f':
  365.             dummy   = base<current ? current-base   : base-current;
  366.             negative= base<current ? TRUE           : FALSE;
  367.             break;
  368.         case    'a':
  369.             dummy=max;
  370.             negative=FALSE;
  371.             break;
  372.         case    'p':
  373.             dummy_2=2; dummy=current;
  374.             negative=FALSE;
  375.             break;
  376.         case    'v':
  377.             dummy_2=5;
  378.             break;
  379.         default:
  380.             goto noforward;
  381.             break;
  382.         }
  383.         i++;
  384. noforward:
  385.         if(dummy_3==1)dummy=max-dummy;
  386.         if(dummy_1==1)dummy=dummy>>10;
  387.         if(dummy_1==2)dummy=dummy>>20;
  388.         switch(dummy_2)
  389.         {
  390.         case    4:
  391.             dummy_2=long_2_string_with_thousand(dummy,&temp_str_1[0],'.',negative);
  392.             for(dummy_1=0;dummy_1<dummy_2;dummy_1++) temp_str[j++]=temp_str_1[dummy_1];
  393.             break;
  394.         case    1:
  395.             dummy_2=long_2_string_with_thousand(dummy,&temp_str_1[0],',',negative);
  396.             for(dummy_1=0;dummy_1<dummy_2;dummy_1++) temp_str[j++]=temp_str_1[dummy_1];
  397.             break;
  398.         case    2:
  399.             dummy_2=0;
  400.             if(negative) SPrintf(&temp_str_1[0],"-%ld",(((dummy>>8)*100)/((max>>8)+1)));
  401.             else         SPrintf(&temp_str_1[0],"%ld", (((dummy>>8)*100)/((max>>8)+1)));
  402.             while ((temp_str_1[dummy_2] != 0)&(dummy_2<64)) temp_str[j++]=temp_str_1[dummy_2++];
  403.             break;
  404.         case    0:
  405.             dummy_2=0;
  406.             if(negative) SPrintf(&temp_str_1[0],"-%ld",dummy);
  407.             else         SPrintf(&temp_str_1[0],"%ld", dummy);
  408.             while ((temp_str_1[dummy_2] != 0)&(dummy_2<64)) temp_str[j++]=temp_str_1[dummy_2++];
  409.             break;
  410.         case    3:
  411.             temp_str[j++]='%';
  412.             break;
  413.         case    5:
  414.             if(special&0xFF000000)temp_str[j++]=(char)((special>>24)&0xFF);
  415.             if(special&0x00FF0000)temp_str[j++]=(char)((special>>16)&0xFF);
  416.             if(special&0x0000FF00)temp_str[j++]=(char)((special>>8) &0xFF);
  417.             temp_str[j++]='\\';
  418.             temp_str[j++]=(char)( special     &0xFF)+0x30;
  419.             break;
  420.         }
  421.     }
  422.     else temp_str[j++]=format[i++];
  423.     }
  424.     temp_str[j++]=0;
  425.     return(temp_str);
  426. }
  427.  
  428. void draw_border_new( struct RastPort *rp,ULONG x, ULONG y, ULONG width, ULONG height, int b_col1, int b_col2 )
  429. {
  430.     width--;height--;
  431.     SetAPen(rp,b_col2);
  432.     RectFill(rp,x+width,y+1,x+width,y+height);
  433.     RectFill(rp,x,y+height,x+width,y+height);
  434.     SetAPen(rp,b_col1);
  435.     RectFill(rp,x,y,x,y+height-1);
  436.     RectFill(rp,x,y,x+width-1,y);
  437. }
  438.  
  439. my_RectFill(struct RastPort *rp,WORD x,WORD y,WORD width,WORD height)
  440. {
  441.     if(((x+width)>1)&&((y+height)>1)) RectFill(rp,x,y,x+width-1,y+height-1);
  442. }
  443.  
  444. putChar_hook(struct Hook *hook,struct Locale *locale,ULONG thechar)
  445. {
  446.     struct GaugeData *data;
  447.     geta4(); data=(struct GaugeData *)hook->h_Data;
  448.     data->clocktxt[data->clockpos++]=(UBYTE)(thechar);
  449. }
  450.  
  451. struct Hook putCharHook = { { 0,0 },(void *)HookEntry,(void *)putChar_hook, NULL };
  452.  
  453. my_Blit(struct RastPort *src, WORD topx, WORD topy, struct RastPort *dest, WORD dtopx, WORD dtopy, WORD width, WORD height)
  454. {
  455.     ClipBlit(src,topx,topy,dest,dtopx,dtopy,width,height,0xC0);
  456. }
  457.  
  458. char *getSTR(struct GaugeData *inst)
  459. {
  460.     switch (inst->current-inst->max)
  461.     {
  462.     case    GAU_err_busy:
  463.         return("Disk is busy");
  464.     case    GAU_err_notmount:
  465.         return("Not mounted");
  466.     case    GAU_err_notpresent:
  467.         return("No disk present");
  468.     case    GAU_err_unreadable:
  469.         return("Disk unreadable");
  470.     case    GAU_err_nodos:
  471.         return("No DOS format");
  472.     case    GAU_err_notavail:
  473.         return("n.a.");
  474.     case    GAU_err_kickstart:
  475.         return("Kickstart disk");
  476.         break;
  477.     default:
  478.         return(formattext(inst->current,inst->base,inst->max,inst->txtfmt,inst->voltype));
  479.     }
  480. }
  481.  
  482. ULONG renderGauge(Class *cl,struct Gadget *g,struct gpRender *msg)
  483. {
  484.     struct  RastPort    *rp;
  485.     struct  BitMap      *work_bm;
  486.     struct  RastPort    *wk_rp,*bg_rp,*hs_rp;
  487.     struct  GaugeData   *inst=INST_DATA(cl,g);
  488.     struct  DateStamp   d_stamp;
  489.     WORD                text_x,w,h;
  490.     WORD                x1,x2,g_x,g_size,g_height,t_length;
  491.     char                *fmt,*mlm;
  492.     LONG                max;
  493.  
  494.     if(rp = ( msg->MethodID == GM_RENDER ) ? msg->gpr_RPort : (struct RastPort *) ObtainGIRPort(msg->gpr_GInfo) )
  495.     {
  496.  
  497.     if(inst->InitNotDone)
  498.     {
  499.         if(work_bm=(struct BitMap *)AllocBitMap(g->Width,g->Height+2,rp->BitMap->Depth,BMF_CLEAR,rp->BitMap))
  500.         {
  501.         if(inst->bg_buffer=(struct RastPort *)AllocVec(sizeof(struct RastPort)+8,MEMF_CLEAR|MEMF_PUBLIC))
  502.         {
  503.             InitRastPort(inst->bg_buffer);
  504.             inst->bg_buffer->BitMap=work_bm;
  505.  
  506.             my_Blit(rp,g->LeftEdge,g->TopEdge,inst->bg_buffer,0,0,g->Width,g->Height);
  507.         }
  508.         else
  509.         {
  510.             FreeBitMap(work_bm);
  511.             return(0L);
  512.         }
  513.         }
  514.         else return(0L);
  515.  
  516.         if(work_bm=(struct BitMap *)AllocBitMap(g->Width,g->Height+2,rp->BitMap->Depth,BMF_CLEAR,inst->bg_buffer->BitMap))
  517.         {
  518.         if(inst->wk_buffer=(struct RastPort *)AllocVec(sizeof(struct RastPort)+8,MEMF_CLEAR|MEMF_PUBLIC))
  519.         {
  520.             InitRastPort(inst->wk_buffer);
  521.             inst->wk_buffer->BitMap=work_bm;
  522.  
  523.             inst->text_y=((g->Height-((inst->textFont->tf_Baseline+inst->textFont->tf_YSize)>>1))>>1);
  524.             if(inst->textFont->tf_Baseline<inst->textFont->tf_YSize)
  525.             {
  526.             inst->text_y+=inst->textFont->tf_Baseline-1;
  527.             if(inst->text_y<inst->textFont->tf_Baseline)inst->text_y=inst->textFont->tf_Baseline;
  528.             }
  529.             else
  530.             {
  531.             inst->text_y+=inst->textFont->tf_YSize-1;
  532.             if(inst->text_y<inst->textFont->tf_YSize)   inst->text_y=inst->textFont->tf_YSize;
  533.             }
  534.  
  535.             SetDrMd(inst->wk_buffer,JAM1);
  536.             SetFont(inst->wk_buffer,inst->textFont);
  537.         }
  538.         else
  539.         {
  540.             FreeBitMap(work_bm);
  541.             return(0L);
  542.         }
  543.         }
  544.         else return(0L);
  545.  
  546.         for(w=0;w<GAU_UsedColors;w++)GetGaugePenNew(msg,inst,&inst->Colors[w],w);
  547.  
  548.         if(inst->type==GAU_Type_histmeter)
  549.         {
  550.         if(work_bm=(struct BitMap *)AllocBitMap(g->Width,g->Height+2,rp->BitMap->Depth,BMF_CLEAR,inst->wk_buffer->BitMap))
  551.         {
  552.             if(inst->hs_buffer=(struct RastPort *)AllocVec(sizeof(struct RastPort)+8,MEMF_CLEAR|MEMF_PUBLIC))
  553.             {
  554.             inst->histpos=0;
  555.             InitRastPort(inst->hs_buffer);
  556.             inst->hs_buffer->BitMap=work_bm;
  557.             SetAPen(inst->hs_buffer,inst->Pens[col_bg]);
  558.             if(inst->StyleBackground)
  559.             {
  560.                 my_Blit(inst->bg_buffer,0,0,inst->hs_buffer,0,0,g->Width,g->Height);
  561.             }
  562.             else
  563.             {
  564.                 my_RectFill(inst->hs_buffer,0,0,g->Width,g->Height);
  565.             }
  566.             }
  567.             else
  568.             {
  569.             FreeBitMap(work_bm);
  570.             return(0L);
  571.             }
  572.         }
  573.         else return(0L);
  574.         }
  575.         inst->old_cur=-1;
  576.         inst->old_bas=-1;
  577.         inst->InitNotDone=FALSE;
  578.     }
  579.  
  580.     wk_rp=inst->wk_buffer;
  581.     bg_rp=inst->bg_buffer;
  582.     switch (inst->type)
  583.     {
  584.         case    GAU_Type_gauge:
  585.             w=g->Width;
  586.             h=g->Height;
  587.             max=inst->max>>8;
  588.             if((inst->current!=inst->old_cur)||(inst->base!=inst->old_bas))
  589.             {
  590.             inst->old_cur=inst->current;
  591.             inst->old_bas=inst->base;
  592.             if(inst->highlight)
  593.             {
  594.                 SetDrMd(bg_rp,JAM1);
  595.                 SetFont(bg_rp,inst->textFont);
  596.                 if(inst->StyleBorder)draw_border_new(bg_rp,inst->labelpos,0,w-inst->labelpos,g->Height,inst->Pens[col_dark],inst->Pens[col_bright]);
  597.                 if(inst->StyleShadowLabel)
  598.                 {
  599.                 SetAPen(bg_rp,inst->Pens[col_dark]);
  600.                 Move(bg_rp,1,inst->text_y+1);
  601.                 Text(bg_rp,inst->txtlbl,my_strlen(inst->txtlbl));
  602.                 }
  603.                 SetAPen(bg_rp,inst->Pens[col_label]);
  604.                 Move(bg_rp,0,inst->text_y);
  605.                 Text(bg_rp,inst->txtlbl,my_strlen(inst->txtlbl));
  606.                 inst->highlight=FALSE;
  607.             }
  608.             my_Blit(bg_rp,0,0,wk_rp,0,0,w,h);
  609.             g_x=1+inst->labelpos;
  610.             g_size=w-inst->labelpos-2;
  611.             g_height=h-2;
  612.             if((!inst->StyleNoGauge)&&(inst->current<inst->max))
  613.             {
  614.                 x1=g_size-(WORD)(((inst->base>>8)   *g_size)/((max)==0 ? 1 : (max)));
  615.                 x2=g_size-(WORD)(((inst->current>>8)*g_size)/((max)==0 ? 1 : (max)));
  616.  
  617.                 if(!inst->StyleNoBase)
  618.                 {
  619.                 if(x1<x2)
  620.                 {
  621.                     SetAPen(wk_rp,inst->Pens[col_base]);
  622.                     my_RectFill(wk_rp,g_x,1,x1,g_height);
  623.                     SetAPen(wk_rp,inst->Pens[col_current]);
  624.                     my_RectFill(wk_rp,g_x+x1,1,x2-x1,g_height);
  625.  
  626.                     if(!inst->StyleBackground)
  627.                     {
  628.                     SetAPen(wk_rp,inst->Pens[col_bg]);
  629.                     my_RectFill(wk_rp,g_x+x2,1,g_size-x2,g_height);
  630.                     }
  631.                     if(inst->Style3D)
  632.                     {
  633.                     if(x1>1)   draw_border_new(wk_rp,g_x,1,x1,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  634.                     if(x2-x1>1)draw_border_new(wk_rp,g_x+x1,1,x2-x1,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  635.                     }
  636.                 }
  637.                 else if(x1>x2)
  638.                 {
  639.                     SetAPen(wk_rp,inst->Pens[col_base]);
  640.                     my_RectFill(wk_rp,g_x,1,x2,g_height);
  641.                     SetAPen(wk_rp,inst->Pens[col_negative]);
  642.                     my_RectFill(wk_rp,g_x+x2,1,x1-x2,g_height);
  643.  
  644.                     if(!inst->StyleBackground)
  645.                     {
  646.                     SetAPen(wk_rp,inst->Pens[col_bg]);
  647.                     my_RectFill(wk_rp,g_x+x1,1,g_size-x1,g_height);
  648.                     }
  649.                     if(inst->Style3D)
  650.                     {
  651.                     if(x2>1)   draw_border_new(wk_rp,g_x,1,x2,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  652.                     if(x1-x2>1)draw_border_new(wk_rp,g_x+x2,1,x1-x2,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  653.                     }
  654.                 }
  655.                 else
  656.                 {
  657.                     SetAPen(wk_rp,inst->Pens[col_base]);
  658.                     my_RectFill(wk_rp,g_x,1,x1,g_height);
  659.  
  660.                     if(!inst->StyleBackground)
  661.                     {
  662.                     SetAPen(wk_rp,inst->Pens[col_bg]);
  663.                     my_RectFill(wk_rp,g_x+x1,1,g_size-x1,g_height);
  664.                     }
  665.                     if((inst->Style3D)&&(x1>1))draw_border_new(wk_rp,g_x,1,x1,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  666.                 }
  667.                 }
  668.                 else
  669.                 {
  670.                 SetAPen(wk_rp,inst->Pens[col_current]);
  671.                 my_RectFill(wk_rp,g_x,1,x2,g_height);
  672.                 if(!inst->StyleBackground)
  673.                 {
  674.                     SetAPen(wk_rp,inst->Pens[col_bg]);
  675.                     my_RectFill(wk_rp,g_x+x2,1,g_size-x2,g_height);
  676.                 }
  677.                 if(inst->Style3D) draw_border_new(wk_rp,g_x,1,x2,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
  678.                 }
  679.             }
  680.             if(!inst->StyleNoFormat)
  681.             {
  682.                 fmt=getSTR(inst);
  683.                 SetAPen(wk_rp,inst->Pens[col_format]);
  684.                 t_length=TextLength(wk_rp,fmt,my_strlen(fmt));
  685.                 if(t_length<(w-inst->labelpos-1))
  686.                 {
  687.                 switch(inst->fmtind)
  688.                 {
  689.                     case    ind_centered:
  690.                         text_x=g_x+((g_size-t_length)>>1);
  691.                         break;
  692.                     case    ind_left:
  693.                         text_x=g_x+2;
  694.                         break;
  695.                     case    ind_right:
  696.                         text_x=w-t_length-3;
  697.                         break;
  698.                 }
  699.                 Move(wk_rp,text_x,inst->text_y);
  700.                 Text(wk_rp,fmt,my_strlen(fmt));
  701.                 }
  702.             }
  703.             my_Blit(wk_rp,0,0,rp,g->LeftEdge,g->TopEdge,w,h);
  704.             }
  705.             break;
  706.         case    GAU_Type_histmeter:
  707.             max=inst->max>>8;
  708.             w=g->Width;
  709.             h=g->Height;
  710.             g_size=h-2;
  711.             hs_rp=inst->hs_buffer;
  712.             if((!inst->StyleNoGauge)&&(inst->current<inst->max))
  713.             {
  714.             x1=(WORD)(((inst->base   >>8)*(g_size-1))/((max)==0 ? 1 : (max)))+1;
  715.             x2=(WORD)(((inst->current>>8)*(g_size-1))/((max)==0 ? 1 : (max)))+1;
  716.             inst->histpos++;
  717.             if(inst->histpos>w-3)
  718.             {
  719.                 WORD dummy;
  720.                 dummy=w-(w>>1)-2;
  721.                 SetAPen(hs_rp,inst->Pens[col_bg]);
  722.                 my_Blit(hs_rp,w>>1,0,hs_rp,0,0,dummy,h);
  723.                 if(inst->StyleBackground)
  724.                 {
  725.                 my_Blit(inst->bg_buffer,dummy,0,inst->hs_buffer,dummy,0,w-dummy,h);
  726.                 }
  727.                 else
  728.                 {
  729.                 RectFill(hs_rp,dummy,0,w,h);
  730.                 }
  731.                 inst->histpos=dummy;
  732.             }
  733.             if(!inst->StyleNoBase)
  734.             {
  735.                 SetAPen(hs_rp,inst->Pens[col_base]);
  736.                 if(x1>x2)
  737.                 {
  738.                 RectFill(hs_rp,inst->histpos,x1,inst->histpos,g_size);
  739.                 SetAPen(hs_rp,inst->Pens[col_current]);
  740.                 RectFill(hs_rp,inst->histpos,x2,inst->histpos,x1);
  741.                 }
  742.                 else if(x1<x2)
  743.                 {
  744.                 RectFill(hs_rp,inst->histpos,x1,inst->histpos,g_size);
  745.                 SetAPen(hs_rp,inst->Pens[col_negative]);
  746.                 RectFill(hs_rp,inst->histpos,x1,inst->histpos,x2);
  747.                 }
  748.                 else
  749.                 {
  750.                 RectFill(hs_rp,inst->histpos,x1,inst->histpos,g_size);
  751.                 }
  752.             }
  753.             else
  754.             {
  755.                 SetAPen(hs_rp,inst->Pens[col_current]);
  756.                 RectFill(hs_rp,inst->histpos,x2,inst->histpos,g_size);
  757.             }
  758.             my_Blit(hs_rp,0,0,wk_rp,0,0,w,h);
  759.             }
  760.             if(inst->StyleBorder)draw_border_new(wk_rp,0,0,w,h,inst->Pens[col_dark],inst->Pens[col_bright]);
  761.             if(!inst->StyleNoFormat)
  762.             {
  763.             fmt=getSTR(inst);
  764.             SetAPen(wk_rp,inst->Pens[col_format]);
  765.             t_length=TextLength(wk_rp,fmt,my_strlen(fmt));
  766.             if(t_length<w)
  767.             {
  768.                 switch(inst->fmtind)
  769.                 {
  770.                 case    ind_centered:
  771.                     text_x=((w-t_length)>>1);
  772.                     break;
  773.                 case    ind_left:
  774.                     text_x=2;
  775.                     break;
  776.                 case    ind_right:
  777.                     text_x=w-t_length-2;
  778.                     break;
  779.                 }
  780.                 Move(wk_rp,text_x,h-3);
  781.                 Text(wk_rp,fmt,my_strlen(fmt));
  782.             }
  783.             }
  784.             my_Blit(wk_rp,0,0,rp,g->LeftEdge,g->TopEdge,w,h);
  785.             break;
  786.         case    GAU_Type_clock:
  787.             w=g->Width-1;
  788.             h=g->Height;
  789.             DateStamp(&d_stamp);
  790.             inst->clockpos=0; putCharHook.h_Data=inst; FormatDate(inst->locale,inst->txtfmt,&d_stamp,&putCharHook);
  791.             if((t_length=TextLength(wk_rp,&inst->clocktxt[0],my_strlen(&inst->clocktxt[0])))<w)
  792.             {
  793.             switch(inst->fmtind)
  794.             {
  795.                 case    ind_centered:
  796.                     text_x=(w-t_length)>>1;
  797.                     break;
  798.                 case    ind_left:
  799.                     text_x=0;
  800.                     break;
  801.                 case    ind_right:
  802.                     text_x=w-t_length-1;
  803.                     break;
  804.             }
  805.             if(inst->oldclockw>t_length)
  806.             {
  807.                 my_Blit(bg_rp,inst->oldclockx,0,wk_rp,inst->oldclockx,0,inst->oldclockw,h);
  808.             }
  809.             else
  810.             {
  811.                 my_Blit(bg_rp,text_x,0,wk_rp,text_x,0,t_length,h);
  812.             }
  813.             if(inst->StyleShadowLabel)
  814.             {
  815.                 SetAPen(wk_rp,inst->Pens[col_dark]);
  816.                 Move(wk_rp,text_x+1,inst->text_y+1);
  817.                 Text(wk_rp,&inst->clocktxt[0],my_strlen(&inst->clocktxt[0]));
  818.             }
  819.             SetAPen(wk_rp,inst->Pens[col_format]);
  820.             Move(wk_rp,text_x,inst->text_y);
  821.             Text(wk_rp,&inst->clocktxt[0],my_strlen(&inst->clocktxt[0]));
  822.             if(inst->oldclockw>t_length)
  823.             {
  824.                 my_Blit(wk_rp,inst->oldclockx,0,rp,g->LeftEdge+inst->oldclockx,g->TopEdge,inst->oldclockw,h);
  825.             }
  826.             else
  827.             {
  828.                 my_Blit(wk_rp,text_x,0,rp,g->LeftEdge+text_x,g->TopEdge,t_length,h);
  829.             }
  830.             inst->oldclockx=text_x;
  831.             inst->oldclockw=t_length;
  832.             }
  833.             break;
  834.     }
  835.     if(msg->MethodID !=GM_RENDER) ReleaseGIRPort(rp);
  836.     return(TRUE);
  837.     }
  838.     else return(FALSE);
  839. }
  840.  
  841. #ifdef __GNUC__
  842. ULONG dispatchGaugeGadget(Class *cl,Object *o, Msg msg)
  843. #else
  844. __geta4 ULONG dispatchGaugeGadget(__a0 Class *cl,__a2 Object *o,__a1 Msg msg)
  845. #endif
  846. {
  847. #ifdef __GNUC__
  848.     geta4();
  849. #endif
  850.     switch( msg->MethodID )
  851.     {
  852.     case    OM_SET:
  853.         setGauge(cl,(struct Gadget *)o,(struct gpRender *)msg);
  854.         return(DoSuperMethodA(cl,o,msg));
  855.     case    GM_RENDER:
  856.         return(renderGauge(cl,(struct Gadget *)o,(struct gpRender *)msg));
  857.     case    OM_NEW:
  858.         if(o = (Object *)DoSuperMethodA(cl, o, msg) )
  859.              return(newGauge(cl,(struct Gadget *)o,(struct gpRender *)msg,INST_DATA(cl, o)));
  860.         else return(0L);
  861.     case    OM_GET:
  862.         return(getGauge(cl,(struct Gadget *)o,(struct gpRender *)msg));
  863.     case    OM_DISPOSE:
  864.         disposeGauge(cl,(struct Gadget *)o,(struct gpRender *)msg);
  865.     default:
  866.         return(DoSuperMethodA(cl,o,msg));
  867.     }
  868. }
  869.  
  870.